const baseUrl = "http://127.0.0.1:3000"
let { token } = wx.getStorageSync('userinfo')

// 参数 "options" 从接口函数传递过来
const request = (options) => {
    return new Promise((resolve,reject) => {
    	// 拼接请求地址
        options.url = baseUrl + options.url
        wx.request({
            url: options.url,
            data: options.data?options.data:{},
            method: options.method,

            header: {
                'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
                'authorization':options.auth?`${token}`:''                           
            },
            success: function (res) {
                // 返回成功信息
                resolve(res)    
            },
            fail: function (error) {
                // 返回错误信息
                console.log(error);
                reject(error)
            }
        })
    })
}
export default request
